using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ThanhChe.Dal.Models.Mapping
{
    public class MediumMap : EntityTypeConfiguration<Medium>
    {
        public MediumMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Title)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Source)
                .IsRequired()
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Media");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.Source).HasColumnName("Source");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.BeatId).HasColumnName("BeatId");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.View).HasColumnName("View");
            this.Property(t => t.CreateDate).HasColumnName("CreateDate");

            // Relationships
            this.HasRequired(t => t.Beat)
                .WithMany(t => t.Media)
                .HasForeignKey(d => d.BeatId);
            this.HasRequired(t => t.UserProfile)
                .WithMany(t => t.Media)
                .HasForeignKey(d => d.UserId);

        }
    }
}
